<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function returnJson($data = [],$code = 200,$msg = ''){
    return json(['data' => $data,'code' => $code,'message' => $msg]);
}



/*
 * 手机型号
 */
function getOS()
{
    $ua = $_SERVER['HTTP_USER_AGENT'];//这里只进行IOS和Android两个操作系统的判断，其他操作系统原理一样
    if (strpos($ua, 'Android') !== false) {//strpos()定位出第一次出现字符串的位置，这里定位为0
        /*preg_match("/(?<=Android )[\d\.]{1,}/", $ua, $version);
        file_put_contents("./pushToken.log",json_encode($version).PHP_EOL, FILE_APPEND);*/
        $arr = explode(' ',$ua);
        return $arr[3].$arr[4].$arr[5].$arr[6];
    } elseif (strpos($ua, 'iPhone') !== false) {
        return $ua;
        /*preg_match("/(?<=CPU iPhone OS )[\d\_]{1,}/", $ua, $version);
        return 'iPhone OS_Version:'.str_replace('_', '.', $version[0]);*/
    } elseif (strpos($ua, 'iPad') !== false) {
        preg_match("/(?<=CPU OS )[\d\_]{1,}/", $ua, $version);
        return 'iPad OS_Version:'.str_replace('_', '.', $version[0]);
    }
}